package the.workshop.bu.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wisteria.framework.web.APIResult;
import org.wisteria.framework.web.QueryResult;
import the.workshop.bu.dto.CustomerDTO;
import the.workshop.bu.dto.req.CustomerQueryReq;
import the.workshop.bu.service.ICustomerService;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @author lei.liu
 * @date 2021/5/6
 */
@RestController
@RequestMapping("/bu/queryCustomer")
public class QueryCustomerController {

    @Resource
    private ICustomerService customerService;

    @GetMapping("/page")
    public APIResult<QueryResult<CustomerDTO>> page(@ModelAttribute CustomerQueryReq req) {
        if (!StringUtils.hasText(req.getFullName())) {
            return APIResult.success(new QueryResult(0L, new ArrayList()));
        }
        return APIResult.success(customerService.pageList(req.toCustomerCondition(), req.getPageNum(), req.getPageSize()));
    }
}
